package com.example.librarymanagementproject2.Common.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.web.SecurityFilterChain;

/**
 * @ClassName SecurityConfig
 * @Description 配置Spring Security
 * @Author Kx
 * @Date 2025/10/20 20:42
 * @Version 1.0
 */
@Configuration
public class SecurityConfig {
    @Bean
    public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
        http.authorizeHttpRequests(auth -> auth
                        // 放行 /users/**、/login/**、/sendEmail/** 所有路径
                        .requestMatchers("/users/**", "/login/**", "/sendEmail/**").permitAll()
                        // 其他路径需要认证
                        .anyRequest().authenticated()
                )
                .csrf(csrf -> csrf.disable()); // 开发环境关闭CSRF
        return http.build();
    }
}
